<?php //pack11class

class GroupsManager {

    public static $groupsDone=false;
    public static $groupsByID=array();
    public static $groupsByName=array();

    public static function getGroup($id=false) {

        if(!self::$groupsDone) self::getgroups();
        if(!$id) return self::$groupsByName;

        if(is_numeric($id)) {
            if(array_key_exists($id, self::$groupsByID)){
                return self::$groupsByID[$id];
            } else {
                return false;
            }
        } else {
            if(array_key_exists($id, self::$groupsByName)){
                return self::$groupsByName[$id];
            } else {
                return false;
            }
        }
    }

    private static function getGroups() {
        $groups=MySQLGet::process("Select * from ".MySQL::TABLE_GROUPS." order by ".LanguagesManager::ssql().";");
        //trace(MySQLGet::getQuery());
        foreach($groups as $row) {
            $group=new Group();
            $group->id=$row["id"];
            $group->label=$row[LanguagesManager::field()];
            $group->system=$row["system"];
            self::$groupsByID[$group->id]=$group;
            self::$groupsByName[$group->system]=$group;
        }
        self::$groupsDone=true;
    }

}
?>
